package StringUtils;

public class Test {

	public static void main(String[] args) {
		System.out.println(deleteSpace("ab__c_d___e"));
		t();
	}

	public static String deleteSpace(String str) {
		String[] s = str.split("_+");
		StringBuffer sb = new StringBuffer();
		sb.append(s[0]);
		for (int i = 1; i < s.length; i++) {
			sb.append("_");
			sb.append(s[i]);
		}
		String b = new String(sb);
		return b;
	}

	public static void testEquals() {
		String a = "abc";
		String b = new String("abc");
		b.intern();
		System.out.println(a == b);
		System.out.println(a.equals(b));
	}

	public static void testHashCode() {
		X x = new X();
		X y = new X();
		System.out.println(x == y);
	}

	public static void t() {
		// 第一种实现:
		String str = "xie xie da jia 谢谢大家";
		System.out.print("逆转后的字符串是:[");

		for (int i = str.length() - 1; i >= 0; i--) {
			char chr = str.charAt(i);
			System.out.print(chr);
		}
		System.out.print("]");
		// 第一种实现输出结果是:逆转后的字符串是:[家大谢谢 aij ad eix eix]

		// 第二种实现:

		// 借助了StringBuffer类的reverse()方法实现,
		String str2 = "good";
		StringBuffer sb = new StringBuffer(str);
		System.out.println("逆转后的字符串是:[" + sb.reverse() + "]");
		// 第二种实现输出结果是:逆转后的字符串是:[doog]
	}
}

class X {
	@Override
	public int hashCode() {
		return 1;
	}
}